#ifndef __L0032_0_SHMFIFO_H__
#define __L0032_0_SHMFIFO_H__

#define L0032_SHMFIFO_FLAGS_CREATOR			1
#define L0032_SHM_FILENAME_MAX				128
#define L0032_PAGESIZE_DEFAULT				sysconf(_SC_PAGE_SIZE)
#define L0032_PAGEALIGN(SZ)					(((SZ) + L0032_PAGESIZE_DEFAULT - 1) & (~(L0032_PAGESIZE_DEFAULT - 1)))
#define L0032_ALIGN(SZ, ALIGNSZ)			(((SZ) + (ALIGNSZ) - 1) & (~((ALIGNSZ) - 1)))
#define L0032_ISPOW2(SZ)					(((SZ) & (SZ - 1)) == 0)

struct l0032_shmfifo {
	size_t sz;

	uint32_t head;
	uint32_t tail;
	uint32_t blobsz;
	uint32_t nblob;
	uint8_t blob[];
};

int l0032_shmfifo_put(void* shmfifo, uint8_t *blob, uint32_t blobsz);
int l0032_shmfifo_get(void* shmfifo, uint8_t *blob, uint32_t blobsz);

int l0032_shmfifo_cnt(void* shmfifo);
int l0032_shmfifo_space(void* shmfifo);

struct l0032_shmfifo* l0032_shmfifo_open(const char* shmname, size_t blobsz, size_t nblobs, int bCreate);
void l0032_shmfifo_close(struct l0032_shmfifo* shmfifo);
uint32_t l0032_shmfifo_drain(struct l0032_shmfifo* shmfifo, uint8_t *mem, uint32_t sz);
void l0032_shmfifo_flush(struct l0032_shmfifo* shmfifo);

#endif
